#ifndef __TIMER_H__
#define __TIMER_H__

#include <map>
#include "xthread.h"

typedef void (*tmCallBack)(void*);

unsigned int GetCurMs();

class xTimer : public lxThread
{
	XX_STATIC_DECLARE(xTimer)
private:
	struct Timer {
		void* user;
		tmCallBack on_timer;

		int repeat;
		unsigned int timerlastrun;
		unsigned int timerInterval; 		          
	};
	std::map<uint64, Timer*> timer_list_;
public:
	xTimer();

	virtual ~xTimer();

	virtual void Run();

	virtual void   CancelTimer(uint64 timeid);

	virtual uint64 RegisterTimer(tmCallBack cb, void* user, unsigned int timerInterval,int repeat = -1);
};

#endif
